package com.joelaws.prototype.server.meeting;

import com.joelaws.prototype.client.meeting.MeetingType;

public class Actions {

	public static class InitAction extends MeetAction {

		public InitAction(long userOne, long userTwo) {
			super(userOne, userTwo, "Waiting for a response.", "Would you like to meet?");

			WhereAction where = new WhereAction(userOne, userTwo);
			super.addUserTwoAction("Yes", where);

			EndAction end = new EndAction(userOne, userTwo);
			super.addUserOneAction("Cancel", end);
			super.addUserTwoAction("No", end);

		}

	}

	public static class EndAction extends MeetAction {

		public EndAction(long userOne, long userTwo) {
			super(userOne, userTwo, "Request Complete.", "Request Complete.");
		}

	}

	public static class WhereAction extends MeetAction {

		public WhereAction(long userOne, long userTwo) {
			super(userOne, userTwo, "What would you like to do?", "What would you like to do?");

			LocationAction location = new LocationAction(userOne, userTwo, MeetingType.Coffee);
			super.addUserOneAction(MeetingType.Coffee.toString(), location);
			super.addUserTwoAction(MeetingType.Coffee.toString(), location);

			location = new LocationAction(userOne, userTwo, MeetingType.Food);
			super.addUserOneAction(MeetingType.Food.toString(), location);
			super.addUserTwoAction(MeetingType.Food.toString(), location);

			location = new LocationAction(userOne, userTwo, MeetingType.Park);
			super.addUserOneAction(MeetingType.Park.toString(), location);
			super.addUserTwoAction(MeetingType.Park.toString(), location);

			EndAction end = new EndAction(userOne, userTwo);
			super.addUserOneAction("Cancel", end);
			super.addUserTwoAction("Cancel", end);

		}

	}

	private static class LocationAction extends MeetAction {

		private MeetingType type;

		public LocationAction(long userOne, long userTwo, MeetingType type) {
			super(userOne, userTwo, "Where would you like to meet for " + type.toString() + "?",
					"Where would you like to meet for " + type.toString() + "?");
			this.type = type;

			addLocationChoices(userOne, userTwo, type);

			EndAction end = new EndAction(userOne, userTwo);
			super.addUserOneAction("Cancel", end);
			super.addUserTwoAction("Cancel", end);

		}

		private void addLocationChoices(long userOne, long userTwo, MeetingType type) {

			TimeAction confirm;
			String loc;

			switch (type) {

			case Coffee:
				loc = "Starbucks";
				confirm = new TimeAction(userOne, userTwo, loc);
				super.addUserOneAction(loc, confirm);
				confirm = new TimeAction(userTwo, userOne, loc);
				super.addUserTwoAction(loc, confirm);
				loc = "DunkinDonuts";
				confirm = new TimeAction(userOne, userTwo, loc);
				super.addUserOneAction(loc, confirm);
				confirm = new TimeAction(userTwo, userOne, loc);
				super.addUserTwoAction(loc, confirm);
				break;

			case Food:
				loc = "Ulysses";
				confirm = new TimeAction(userOne, userTwo, loc);
				super.addUserOneAction(loc, confirm);
				confirm = new TimeAction(userTwo, userOne, loc);
				super.addUserTwoAction(loc, confirm);
				loc = "SoupMan";
				confirm = new TimeAction(userOne, userTwo, loc);
				super.addUserOneAction(loc, confirm);
				confirm = new TimeAction(userTwo, userOne, loc);
				super.addUserTwoAction(loc, confirm);
				break;

			case Park:
				loc = "BatteryPark";
				confirm = new TimeAction(userOne, userTwo, loc);
				super.addUserOneAction(loc, confirm);
				confirm = new TimeAction(userTwo, userOne, loc);
				super.addUserTwoAction(loc, confirm);
				break;
			}
		}

		@Override
		public MeetingType getMeetingType() {
			return type;
		}

	}

	public static class TimeAction extends MeetAction {

		public TimeAction(long userOne, long userTwo, String location) {
			super(userOne, userTwo, "What time do you want to meet at " + location + "?",
					"What time do you want to meet at " + location + "?");

			for (int i = 0; i < 24; i++) {
				String time = Integer.toString(i);
				ConfirmationAction action = new ConfirmationAction(userOne, userTwo, location, time);
				super.addUserOneAction(time, action);
				action = new ConfirmationAction(userTwo, userOne, location,time);
				super.addUserTwoAction(time, action);
			}

			EndAction end = new EndAction(userOne, userTwo);
			super.addUserOneAction("Cancel", end);
			super.addUserTwoAction("Cancel", end);
		}
	}

	public static class ConfirmationAction extends MeetAction {

		public ConfirmationAction(long userOne, long userTwo, String location, String time) {
			super(userOne, userTwo, "Verifying meeting at " + location + " at " + time + ":00 with other user.",
					"Other user would you like to meet at " + location + " at " + time + ":00 is that ok?");

			FinishedAction finished = new FinishedAction(userOne, userTwo, location);
			super.addUserTwoAction("Yes", finished);

			EndAction end = new EndAction(userOne, userTwo);
			super.addUserOneAction("Cancel", end);
			super.addUserTwoAction("No", end);
		}
	}

	public static class FinishedAction extends MeetAction {

		public FinishedAction(long userOne, long userTwo, String location) {
			super(userOne, userTwo, "Meeting setup at " + location, "Meeting setup at " + location);

		}

	}

}
